{extend name='base'/}
{block name='content'}
<ol class="breadcrumb" style="background-color: #f9f9f9;padding:8px 0;margin-bottom:10px;">
    <li>
        <a href=""><i class="fa fa-cogs"></i>
            栏目管理</a>
    </li>
    <li class="active">
        <a href="">栏目列表</a>
    </li>
</ol>
<ul class="nav nav-tabs" role="tablist">
    <li class="active"><a href="">栏目列表</a></li>
    <li><a href="{:url('admin/Category/store')}">添加栏目</a></li>
</ul>
<form action="" method="post">
    <div class="panel panel-default">
        <div class="panel-body">
            <table class="table table-hover">
                <thead>
                <tr>
                    <th width="10%">编号</th>
                    <th width="30%">栏目名称</th>
                    <th width="">显示顺序 (降序)</th>
                    <th width="200">操作</th>
                </tr>
                </thead>
                <tbody>
                {foreach name='field' key='key' item='value'}
                <tr>
                    <td>{$value['cate_id']}</td>
                    <td>{$value['cate_name']}</td>
                    <td>
                        <input type="text" style="width: 50px" class="form-control" value="{$value['cate_sort']}"
                               onblur="changeSort(this,{$value['cate_id']})" >
                    </td>
                    <td>
                        <div class="btn-group">
                            <button data-toggle="dropdown" class="btn btn-primary btn-xs dropdown-toggle">操作 <span
                                    class="caret"></span></button>
                            <ul class="dropdown-menu dropdown-menu-right">
                                <li><a href="{:url('admin/Category/addSon',['cate_id'=>$value['cate_id']])}">添加子类</a>
                                </li>
                                <li><a href="{:url('admin/Category/edit',['cate_id'=>$value['cate_id']])}">编辑</a></li>
                                <li class="divider"></li>
                                <li><a onclick="del({$value['cate_id']},{$value['pid']})">删除</a></li>
                            </ul>
                        </div>
                    </td>
                </tr>
                {/foreach}
                </tbody>
            </table>
        </div>
    </div>
</form>
<div class="pagination pagination-sm pull-right">
</div>
<!-- 信息删除确认 -->
<div class="modal fade" id="delcfmModel" data-toggle="modal">
    <div class="modal-dialog">
        <div class="modal-content message_align">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">×</span></button>
                <h4 class="modal-title">提示信息</h4>
            </div>
            <div class="modal-body">
                <p>您确认要删除吗？</p>
            </div>
            <div class="modal-footer">
                <a class="btn btn-default" data-dismiss="modal">取消</a>
                <form action="delCate" method="post" style="display: inline-block">
                    <input id="del_id" type="hidden" name="cate_id" value="">
                    <input id="del_pid" type="hidden" name="pid" value="">
                    <button class="btn btn-primary" type="submit">确定</button>
                </form>
            </div>
        </div>
    </div>
</div>
<!-- 信息删除确认end -->

<script>
    function del(id, pid) {
        $('#delcfmModel').modal('show');
        $('#del_id').val(id);
        $('#del_pid').val(pid);
    };

    //修改排序
    function changeSort(obj, cate_id) {
        //获取修改完成之后的排序值
        var cate_sort = $(obj).val();

        $.ajax({
            type : "POST",
            url: "{:url('admin/Category/changeSort')}",
            data: {
                cate_sort: cate_sort,
                cate_id: cate_id
            },
            dataType:'text',
            success: function (res) {
                alert('修改成功')
            },
            error: function (res) {
                console.log(res);
                // alert(e);
            }
        })
    }
</script>
{/block}
